<!DOCTYPE html>
<!--[if IE 9]>         <html class="no-js lt-ie10" lang="en"> <![endif]-->
<!--[if gt IE 9]><!-->
<html class="no-js" lang="en">
	<!--<![endif]-->

	<head>
		<meta charset="utf-8">

		<title>我的调查——问卷调查系统</title>

		<meta name="description" content="AppUI is a Web App Bootstrap Admin Template created by pixelcave and published on Themeforest">
		<meta name="author" content="pixelcave">
		<meta name="robots" content="noindex, nofollow">

		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

		<!-- Icons -->
		<!-- The following icons can be replaced with your own, they are used by desktop and mobile browsers -->
		<link rel="shortcut icon" href="img/favicon.png">
		<link rel="apple-touch-icon" href="img/icon57.png" sizes="57x57">
		<link rel="apple-touch-icon" href="img/icon72.png" sizes="72x72">
		<link rel="apple-touch-icon" href="img/icon76.png" sizes="76x76">
		<link rel="apple-touch-icon" href="img/icon114.png" sizes="114x114">
		<link rel="apple-touch-icon" href="img/icon120.png" sizes="120x120">
		<link rel="apple-touch-icon" href="img/icon144.png" sizes="144x144">
		<link rel="apple-touch-icon" href="img/icon152.png" sizes="152x152">
		<link rel="apple-touch-icon" href="img/icon180.png" sizes="180x180">
		<!-- END Icons -->

		<!-- Stylesheets -->
		<!-- Bootstrap is included in its original form, unaltered -->
		<link rel="stylesheet" href="css/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" href="css/daterangepicker.css" />

		<!-- Related styles of various icon packs and plugins -->
		<link rel="stylesheet" href="css/plugins.css">
		<link rel="stylesheet" href="css/page.css"/>
		<link rel="stylesheet" href="css/laypage.css">
		<!-- The main stylesheet of this template. All Bootstrap overwrites are defined in here -->
		<link rel="stylesheet" href="css/main.css">

		<!-- Include a specific file here from css/themes/ folder to alter the default theme of the template -->

		<!-- The themes stylesheet of this template (for using specific theme color in individual elements - must included last) -->
		<link rel="stylesheet" href="css/themes/amethyst.css">
		<!-- END Stylesheets -->

		<!-- Modernizr (browser feature detection library) -->
		<script src="js/vendor/modernizr-3.3.1.min.js"></script>
	</head>

	<body>
		<!-- Page Wrapper -->
		<!-- In the PHP version you can set the following options from inc/config file -->
		<!--
            Available classes:

            'page-loading'      enables page preloader
        -->
		<div id="page-wrapper" class="page-loading">
			<!-- Preloader -->
			<!-- Preloader functionality (initialized in js/app.js) - pageLoading() -->
			<!-- Used only if page preloader enabled from inc/config (PHP version) or the class 'page-loading' is added in #page-wrapper element (HTML version) -->
			<div class="preloader">
				<div class="inner">
					<!-- Animation spinner for all modern browsers -->
					<div class="preloader-spinner themed-background hidden-lt-ie10"></div>

					<!-- Text for IE9 -->
					<h3 class="text-primary visible-lt-ie10"><strong>Loading..</strong></h3>
				</div>
			</div>
			<!-- END Preloader -->

			<!-- Page Container -->
			<!-- In the PHP version you can set the following options from inc/config file -->
			<!--
                Available #page-container classes:

                'sidebar-light'                                 for a light main sidebar (You can add it along with any other class)

                'sidebar-visible-lg-mini'                       main sidebar condensed - Mini Navigation (> 991px)
                'sidebar-visible-lg-full'                       main sidebar full - Full Navigation (> 991px)

                'sidebar-alt-visible-lg'                        alternative sidebar visible by default (> 991px) (You can add it along with any other class)

                'header-fixed-top'                              has to be added only if the class 'navbar-fixed-top' was added on header.navbar
                'header-fixed-bottom'                           has to be added only if the class 'navbar-fixed-bottom' was added on header.navbar

                'fixed-width'                                   for a fixed width layout (can only be used with a static header/main sidebar layout)

                'enable-cookies'                                enables cookies for remembering active color theme when changed from the sidebar links (You can add it along with any other class)
            -->
			<div id="page-container" class="header-fixed-top sidebar-visible-lg-full sidebar-light">
				<!-- Alternative Sidebar -->
				<div id="sidebar-alt" tabindex="-1" aria-hidden="true">
					<!-- Toggle Alternative Sidebar Button (visible only in static layout) -->
					<a href="javascript:void(0)" id="sidebar-alt-close" onclick="App.sidebar('toggle-sidebar-alt');"><i class="fa fa-times"></i></a>
				</div>
				<!-- END Alternative Sidebar -->

				<!-- Main Sidebar -->
				<div id="sidebar">
					<!-- Sidebar Brand -->
					<div id="sidebar-brand" class="themed-background">
						<a href="" class="sidebar-title">
							<i class="fa fa-cube"></i> <span class="sidebar-nav-mini-hide"><strong>问道</strong></span>
						</a>
					</div>
					<!-- END Sidebar Brand -->

					<!-- Wrapper for scrolling functionality -->
					<div id="sidebar-scroll">
						<!-- Sidebar Content -->
						<div class="sidebar-content">
							<!-- Sidebar Navigation -->
							<ul class="sidebar-nav">
								<li>
									<a href="questionnaire.html"><i class="gi gi-compass sidebar-nav-icon"></i><span class="sidebar-nav-mini-hide">问卷</span></a>
								</li>
								<li class="active">
									<a href="survey.html"><i class="fa fa-rocket sidebar-nav-icon"></i><span class="sidebar-nav-mini-hide">调查</span></a>
								</li>
								<li>
									<a href="sendmsg.html"><i class="gi gi-compass sidebar-nav-icon"></i><span class="sidebar-nav-mini-hide">通知池</span></a>
								</li>
							</ul>
							<!-- END Sidebar Navigation -->
						</div>
						<!-- END Sidebar Content -->
					</div>
					<!-- END Wrapper for scrolling functionality -->
					<div style="position: absolute; bottom: 4%;margin: 0 4%;">
						<a href="http://qure.zjgsu.edu.cn/ghc/organize/login.html" style="text-decoration: underline;color: gray;">人员管理系统</a>
						<a href="#modal-info" data-toggle="modal"  style="color: gray;text-decoration: underline;">联系我们</a>
					
					</div>
				</div>
				<!-- END Main Sidebar -->

				<!-- Main Container -->
				<div id="main-container">
					<!-- Header -->
					<!-- In the PHP version you can set the following options from inc/config file -->
					<!--
                        Available header.navbar classes:

                        'navbar-default'            for the default light header
                        'navbar-inverse'            for an alternative dark header

                        'navbar-fixed-top'          for a top fixed header (fixed main sidebar with scroll will be auto initialized, functionality can be found in js/app.js - handleSidebar())
                            'header-fixed-top'      has to be added on #page-container only if the class 'navbar-fixed-top' was added

                        'navbar-fixed-bottom'       for a bottom fixed header (fixed main sidebar with scroll will be auto initialized, functionality can be found in js/app.js - handleSidebar()))
                            'header-fixed-bottom'   has to be added on #page-container only if the class 'navbar-fixed-bottom' was added
                    -->
					<header class="navbar navbar-inverse navbar-fixed-top">
						<!-- Left Header Navigation -->
						<ul class="nav navbar-nav-custom">
							<!-- Main Sidebar Toggle Button -->
							<li>
								<a href="javascript:void(0)" onclick="App.sidebar('toggle-sidebar');this.blur();">
									<i class="fa fa-ellipsis-v fa-fw animation-fadeInRight" id="sidebar-toggle-mini"></i>
									<i class="fa fa-bars fa-fw animation-fadeInRight" id="sidebar-toggle-full"></i>
								</a>
							</li>
							<!-- END Main Sidebar Toggle Button -->

							<!-- Header Link -->
							<li class="hidden-xs animation-fadeInQuick">
								<a href=""><strong>我的调查</strong></a>
							</li>
							<!-- END Header Link -->
						</ul>
						<!-- END Left Header Navigation -->

						<!-- Right Header Navigation -->
						<ul class="nav navbar-nav-custom pull-right">
							<!-- User Dropdown -->
							<li class="dropdown">
								<span> </span>
								<a onclick="logout()" class="dropdown-toggle" data-toggle="dropdown">
									注销
								</a>
							</li>
								<!-- END User Dropdown -->
						</ul>
						<!-- END Right Header Navigation -->
					</header>
					<!-- END Header -->

					<!-- Page content -->
					<div id="page-content">
						<!-- Tickets Header -->
						<div class="content-header">
							<div class="row">
								<div class="col-sm-6">
									<div class="header-section">
										<button class="btn btn-primary" onclick="createSurvey()">新建调查</button>
									</div>
								</div>
								<div class="col-sm-3 col-sm-offset-3 hidden-xs">
									<div class="header-section">
										<div class="input-group">
											<input type="text" id="input-search-survey" name="example-input1-group2" class="form-control"  placeholder="搜   索" style="text-align: center";>
											<span class="input-group-btn">
                                                <button type="button" class="btn btn-effect-ripple btn-primary"><i class="fa fa-search"></i></button>
                                            </span>
										</div>
									</div>
								</div>
							</div>
						</div>
						<!-- END Tickets Header -->

						<!-- Tickets Content -->
						<div class="row">
							<div class="col-md-3 col-lg-3">
								<!-- Menu Block -->
								<div class="block full hidden">
									<!-- Menu Title -->
									<div class="block-title clearfix">
										<h2>问卷类型</h2>
									</div>
									<!-- END Menu Title -->

									<!-- Menu Content -->
									<ul class="nav nav-pills nav-stacked">
										<li id="select-type-all" class="active">
											<a>
												<strong>全部</strong>
											</a>
										</li>
										<li id="select-type-open">
											<a>
												<strong>匿名</strong>
											</a>
										</li>
										<li id="select-type-private">
											<a>
												<strong>实名</strong>
											</a>
										</li>
									</ul>
									<!-- END Menu Content -->
								</div>
								<!-- END Menu Block -->

								<!-- Menu Block -->
								<div class="block full">
									<!-- Menu Title -->
									<div class="block-title clearfix">
										<h2>问卷状态</h2>
									</div>
									<!-- END Menu Title -->

									<!-- Menu Content -->
									<ul class="nav nav-pills nav-stacked">
										<li id="select-state-all" class="active">
											<a>
												<strong>全部</strong>
											</a>
										</li>
										<li id="select-state-notStarted">
											<a>
												<strong>未开始</strong>
											</a>
										</li>
										<li id="select-state-running">
											<a>
												<strong>运行中</strong>
											</a>
										</li>
										<li id="select-state-paused">
											<a>
												<strong>暂停中</strong>
											</a>
										</li>
										<li id="select-state-ended">
											<a>
												<strong>已结束</strong>
											</a>
										</li>
									</ul>
									<!-- END Menu Content -->
								</div>
								<!-- END Menu Block -->

							</div>
							<div class="col-md-9 col-lg-9">
								<!-- Menu Block -->
								<div class="block full" id="survey-list">
									<!-- Menu Content -->
									<!-- Menu Block -->
									
								</div>
								<div id='layui'style="padding: 0 0 20% 0;"></div>
								<!-- END Menu Block -->
								<!-- delete Modal -->
								<div id="modal-delete" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
									<div class="modal-dialog">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
												<h3 class="modal-title"><strong>提示</strong></h3>
											</div>
											<div class="modal-body">
												是否删除该调查？
											</div>
											<div class="modal-footer">
												<button type="button" class="btn btn-effect-ripple btn-primary" onclick="deleteSurvey()">确定</button>
												<button type="button" class="btn btn-effect-ripple btn-danger" data-dismiss="modal">取消</button>
											</div>
										</div>
									</div>
								</div>
								<!-- END delete Modal -->
								<div id="modal-nogroup" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
									<div class="modal-dialog">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
												<h3 class="modal-title"><strong>提示</strong></h3>
											</div>
											<div class="modal-body">
												当前调查还未绑定人员组，暂无结果可查看
											</div>
											
										</div>
										<div class="modal-footer">
												 
												<button type="button" class="btn btn-effect-ripple btn-danger" data-dismiss="modal">确定</button>
										</div>
									</div>
								</div>
								<!-- notStart Modal -->
								<div id="modal-notStart" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
									<div class="modal-dialog">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
												<h3 class="modal-title"><strong>提示</strong></h3>
											</div>
											<div class="modal-body">
												该调查处在未开始状态，是否更改调查周期，运行此调查？
												<div class="row"  style="margin: 4% 0 0 0;">
													<div class="col-md-12">
														
															<div class="input-group input-daterange" data-date-format="yyyy-mm-dd" style="display: inline;">
																<input type="text" id="notStart-startTime" name="example-daterange1" class="form-control " placeholder="起始日期" style="width: 40%;display: inline;">
															</div>
															<div class="input-group input-daterange" data-date-format="yyyy-mm-dd" style="display: inline;">
																<input type="text" id="notStart-endTime" name="example-daterange2" class="form-control" placeholder="终止日期" style="width: 40%;display: inline;" >
															</div>
													</div>
												</div>
												<div id="quesnote1" class="note" style='color:red;width:fit-content;margin-top: 2%;margin-left: 2.4%;'></div>
											</div>
											<div class="modal-footer">
												<button type="button" class="btn btn-effect-ripple btn-primary" onclick="chgState1()">确定</button>
												<button type="button" class="btn btn-effect-ripple btn-danger" data-dismiss="modal">取消</button>
											</div>
										</div>
									</div>
								</div>
								<!-- END notStart Modal -->
								<!-- ended Modal -->
								<div id="modal-ended" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
									<div class="modal-dialog">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
												<h3 class="modal-title"><strong>提示</strong></h3>
											</div>
											<div class="modal-body">
												该调查处在已结束状态，是否更改调查周期，运行此调查？
												<div class="row"  style="margin: 4% 0 0 0;">
													<div class="col-md-12" >
														
															<div class="input-group input-daterange" data-date-format="yyyy-mm-dd" style="display: inline;">
															<input type="text" id="ended-startTime" name="example-daterange1" class="form-control " placeholder="起始日期" style="width: 40%;">
															</div>
															<div class="input-group input-daterange" data-date-format="yyyy-mm-dd" style="display: inline;">
															<input type="text" id="ended-endTime" name="example-daterange2" class="form-control" placeholder="终止日期" style="width: 40%;">
															</div>
													</div>
												</div>
												<div id="quesnote2" class="note" style='color:red;width:fit-content;margin-top: 2%;margin-left: 2.4%;'></div>
											</div>
											<div class="modal-footer">
												<button type="button" class="btn btn-effect-ripple btn-primary" onclick="chgState2()">确定</button>
												<button type="button" class="btn btn-effect-ripple btn-danger" data-dismiss="modal">取消</button>
											</div>
										</div>
									</div>
								</div>
								<!-- END ended Modal -->
								<!-- chgTime Modal -->
								<div id="modal-chgTime" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
									<div class="modal-dialog">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
												<h3 class="modal-title"><strong>提示</strong></h3>
											</div>
											<div class="modal-body">
												请选择更改后的调查周期
												<div class="row" style="margin: 4% 0 0 0;">
													<div class="col-md-12">
															<div class="input-group input-daterange" data-date-format="yyyy-mm-dd" style="display: inline;">
																<input type="text" id="setTime-startTime" name="example-daterange1" class="form-control " placeholder="起始日期"  style="width: 40%;">
															</div>
															<div class="input-group input-daterange" data-date-format="yyyy-mm-dd" style="display: inline;">
																<input type="text" id="setTime-endTime" name="example-daterange2" class="form-control" placeholder="终止日期" style="width: 40%;" >
															</div>
													</div>
												</div>
												<div id="quesnote" class="note" style='color:red;width:fit-content;margin-top: 2%;margin-left: 2.4%;'></div>
											</div>
											<div class="modal-footer">
												<button type="button" class="btn btn-effect-ripple btn-primary" onclick="setTime()">确定</button>
												<button type="button" class="btn btn-effect-ripple btn-danger" data-dismiss="modal">取消</button>
											</div>
										</div>
									</div>
								</div>
								<!-- END chgTime Modal -->
								<div id="modal-info" class="modal" tabindex="-1" role="dialog" aria-hidden="true" style="z-index: 2000;">
									<div class="modal-dialog">
										<div class="modal-content">
										<div class="modal-header">
										<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
										<h3 class="modal-title"><strong>维护人员信息：</strong></h3>
									</div>
									<div class="modal-body">
										<p>手机号：18758263422（543422）</p>
										<p>微 信：F_10086_</p>
										<p>Q Q ：1390415732</p>
									</div>
									<div class="modal-footer">
										<button type="button" class="btn btn-effect-ripple btn-primary" data-dismiss="modal">确定</button>
									</div>
								</div>
							</div>
						</div>
						<!-- END Tickets Content -->
					</div>
					<!-- END Page Content -->
				</div>
				<!-- END Main Container -->
			</div>
			<!-- END Page Container -->
		</div>
		<!-- END Page Wrapper -->

		<!-- jQuery, Bootstrap, jQuery plugins and Custom JS code -->
		<script src="js/vendor/jquery-2.2.4.min.js"></script>
		<script src="js/vendor/bootstrap.min.js"></script>
		<script src="js/plugins.js"></script>
		<script src="js/app.js"></script>
		<script src="js/lay/modules/laypage.js"></script>
		<script src="js/layui.js"></script>
		<script src="js/daterangepicker.js"></script>
		<script src="js/moment.js"></script>
		<script src="js/layui.all.js"></script>
		<!-- Load and execute javascript code used only in this page -->
		<script src="js/pages/readyTickets.js"></script>
		<script>
			//url
			var ip;
			var configJson='js/confing.json'
			$.getJSON(configJson,function(data){
				ip=data.url;
			});
			$(function() {
				$.getJSON(configJson,function(data){
				ip=data.urlip;
				identi()
				time();
				getList();
				identi();
				$('body').on('hidden.bs.modal', '.modal', function () {
   					$(this).removeData("example-daterange2");
   					$(".note").html('')
					});
				});
			});
			var	getUrl = '/survey/list',
				chgStateUrl = '/survey/changeStates',
				setTimeUrl = '/survey/setTime';
			var chgId = '';
			//判断登录状态
			function identi()
			{
				$.ajax({
     				type: "get",
   					url: ip+"/user/type",
  					data:{
  						
  					},
    				async: true,
    				dataType: "json",
     				xhrFields: {withCredentials: true},
    				crossDomain:true,
    				success: function(res) {
    					console.log("sssss")
    					console.log(res)
						if(res.code==-1)
						{
							 window.location.replace("login.html")
							 window.history.forward(1);
						}
    				},
    				async:false
     			});
			}
			
			var total;
			function getList(pageconf) {
				total=0;
				if(!pageconf){
					pageconf={};
					pageconf.pageSize=6;
					pageconf.currentPage=1;
				}
				
				$.ajax({
					type: "get",
					url: ip + getUrl,
					data: {
						"page":pageconf.currentPage,
						"size":pageconf.pageSize,
					},
					dataType: "json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log(res);
						//填充
						//setList(res.data.datas);
						if(res.data.content.length){
							total=res.data.totalElements;
							getPage(pageconf,res.data.content)
							if($("#layui").hasClass('hidden'))
							{
								$("#layui").removeClass("hidden")
							}
						}else{
							getPage(pageconf,0)
							$("#survey-list").html("<div style='color: darkgrey;text-align: center;'>当前调查列表为空</div>")
							$("#layui").addClass("hidden")
						}
					},
					async: true
				});
			}

			function logout(){
				$.ajax({
					type:"get",
					url:ip+"/logout",
					data:{},
					async:true,
					dataType: "json",
					xhrFields: {withCredentials: true},
      				crossDomain:true,
      				success:function(res)
      				{
      					 if(!res.code){
      						window.location.replace("login.html")
							window.history.forward();
      					 }
      				}
				});	
			}

			function getPage(pageconf,date){
				layui.use(['laypage','layer'],function(){
					var laypage=layui.laypage;
					laypage.render({
						elem:'layui',
						count:total,
						skin:'#7c62ad',
						curr:pageconf.currentPage,
						limit:pageconf.pageSize,
						limits:[4,8,12],
						skip:true,
						first:"首页",
						last:"尾页",
						layout:['count','skip' ,'next', 'prev'],
						jump:function(obj,first){
							page=obj.curr;
							limit=obj.limit;
							if(!first){
								 pageconf.currentPage=obj.curr;
								 pageconf.pageSize=obj.limit;
								 getList(pageconf);
							}
						}
					});
					setList(date);
				});
			}
			
			function setList(data) {
				var content = '';
				$.each(data, function(index, value) {
					//获取问卷数量
					getQuesNum(value.id);
					if(value.privately) {
						getQuesAllNum(value.id);
					}

					//调查状态判断
					var status = '';
					var chgbtn = '';
					if(value.state == "running") {
						status = "运行中";
						chgbtn = '<button class="btn btn-warning" style="width: 80px;" onclick="chgState(this.name)" name="' + value.id + '"><i class="fa fa-pause-circle"></i>&nbsp;&nbsp;暂停</button>';
					} else if(value.state == "paused") {
						status = "暂停中";
						chgbtn = '<button class="btn btn-success" style="width: 80px;" onclick="chgState(this.name)" name="' + value.id + '"><i class="fa fa-play-circle"></i>&nbsp;&nbsp;运行</button>';
					} else if(value.state == "notStarted") {
						status = "未开始";
						chgbtn = '<a href="#modal-notStart" onclick="setnostarttime(this.name)" data-toggle="modal" class="btn btn-success" style="width: 80px;" name="' + value.id + '"><i class="fa fa-play-circle"></i>&nbsp;&nbsp;运行</a>';
					} else if(value.state == "ended") {
						status = "已结束";
						var st=(value.startTime).toString()
						console.log("aaaa"+st)
						chgbtn = '<a href="#modal-ended" onclick="seteddtime(this.id,this.name)" data-toggle="modal" class="btn btn-success" style="width: 80px;" name="' + value.id + '" id="'+st+'"><i class="fa fa-play-circle"></i>&nbsp;&nbsp;运行</a>';
					}
					if(value.privately) {//true 实名
						content = content + '<div class="block full"><div class="block-title clearfix"><h1>' + value.title + '</h1><span class="pull-right"><h3>答卷：' + currCount + '/' + allCount + '</h3><h3>' +'实名 :' + status + '</h3><a href="#modal-chgTime"  data-toggle="modal" onclick="transId1(this.name,this.id)" name="' + value.id + '" id="'+status +'">周期：' + value.startTime + '~' + value.endTime + '</a></span></div><button class="btn btn-primary" style="width: 80px;" onclick="surveyDetail(this.name, ' + value.privately + ')" name="' + value.id + '">详情</button><div class="btn-group" style="margin-left: 20px;"><a href="javascript:void(0)"'+ (value.surveyGroupId ? 'data-toggle="dropdown"' : '')+(value.surveyGroupId ? '' : 'disabled')+' class="btn btn-default dropdown-toggle"'+(value.surveyGroupId ? '' : 'onclick="nogroup()"')  +' style="width: 80px;">结果<span class="caret"></span></a><ul class="dropdown-menu text-left"><li><a onclick="completeDetail(this.name)" name="' + value.id + '">完成情况</a></li><li><a  onclick="checkAnswer(this.name)" name="' + value.id + '">答案分析</a></li><li><a onclick="analysisAnswer(this.name)" name="' + value.id + '">结果查看</a></li></ul></div><div class="pull-right">' + chgbtn + '<a href="#modal-delete" data-toggle="modal"  onclick="trasnDelId(this.name)" name="' + value.id + '" class="btn btn-danger" style="margin-left: 20px;width: 80px;"><i class="fa fa-trash"></i>&nbsp;&nbsp;删除</a></div></div>';
					}else {
						content = content + '<div class="block full"><div class="block-title clearfix"><h1>' + value.title + '</h1><span class="pull-right"><h3>答卷：' + currCount + '</h3><h3>' +'匿名'+ '：' + status + '</h3><a href="#modal-chgTime"  data-toggle="modal" onclick="transId1(this.name,this.id)" name="' + value.id + '" id="'+status+'">周期：' + value.startTime + '~' + value.endTime + '</a></span></div><button class="btn btn-primary" style="width: 80px;" onclick="surveyDetail(this.name, ' + value.privately + ')" name="' + value.id + '">详情</button><div class="btn-group" style="margin-left: 20px;"><a href="javascript:void(0)"  data-toggle="dropdown" class="btn btn-default dropdown-toggle" style="width: 80px;">结果<span class="caret"></span></a><ul class="dropdown-menu text-left"><li><a onclick="completeDetail(this.name)" name="' + value.id + '">完成情况</a></li><li><a  onclick="checkAnswer(this.name)" name="' + value.id + '">答案分析</a></li></ul></div><div class="pull-right">' + chgbtn + '<a href="#modal-delete" data-toggle="modal"  onclick="trasnDelId(this.name)" name="' + value.id + '" class="btn btn-danger" style="margin-left: 20px;width: 80px;"><i class="fa fa-trash"></i>&nbsp;&nbsp;删除</a></div></div>';
					}
					 
				});
				$("#survey-list").html(content);
			}

			
			//判断是否绑定了人员组
			function nogroup()
			{
				$("#modal-nogroup").modal("toggle")
				 
			}
			
			var currCount = 0,
				allCount = 0;

			function getQuesNum(id) {
				var getNumUrl = '/submit/count';

				$.ajax({
					type: "get",
					url: ip + getNumUrl,
					data: {
						surveyId: id
					},
					dataType: "json",
					//					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log("===");
						console.log(res.data);
						currCount = res.data;
						//						window.location.href="importMember.html";
						//						window.event.returnValue=false;
					},
					async: false
				});
			}
			
			function getQuesAllNum(id) {
				var getAllNumUrl = '/submit/totalCount';

				$.ajax({
					type: "get",
					url: ip + getAllNumUrl,
					data: {
						surveyId: id
					},
					dataType: "json",
					//					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log("===");
						console.log(res.data);
						allCount = res.data;
						//						window.location.href="importMember.html";
						//						window.event.returnValue=false;
					},
					async: false
				});
			}


			
			//修改调查周期================================
			function setTime() {
				$.ajax({
					type: "put",
					url: ip + setTimeUrl,
					data: {
						id: chgId,
						startTime: $("#setTime-startTime").val(),
						endTime: $("#setTime-endTime").val()
					},
					dataType: "json",
					//					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log(res);
						//location.reload();
						 if(!res.code){
							$(".layui-laypage-btn").click();
							$("#modal-chgTime").modal("toggle")
						}else{
							console.log("dddd")
							$("#quesnote").html(res.msg)
						}
					},
					async: true
				});
			}
			
			var currentdate=''
			function time(){
				var date = new Date();
        		var seperator1 = "-";
       		 	var year = date.getFullYear();
       			var month = date.getMonth() + 1;
        		var strDate = date.getDate();
      			if (month >= 1 && month <= 9) {
            		month = "0" + month;
       			 }
     			if (strDate >= 0 && strDate <= 9) {
           			 strDate = "0" + strDate;
       			 }
      			currentdate = year + seperator1 + month + seperator1 + strDate;
			}
			function setnostarttime(id){
				chgId = id;
				console.log(chgId);
      			console.log(currentdate)
				$("#notStart-startTime").val(currentdate);
			}
			 
			
			//未开始
			function chgState1() {
				$.ajax({
					type: "put",
					url: ip + setTimeUrl,
					data: {
						id: chgId,
						startTime: $("#notStart-startTime").val(),
						endTime: $("#notStart-endTime").val()
					},
					dataType: "json",
					//					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log(res);
						if(res.code == 0) {
							//先更改周期再更改状态
							$("#modal-notStart").modal("toggle")
							$(".layui-laypage-btn").click();
						}else{
							$("#quesnote1").html(res.msg)
						}
						
					},
					async: true
				});
			}
			function seteddtime(time,id){
				chgId = id;
				console.log(chgId);
				console.log(time)
				$("#ended-startTime").val(time)
				$("#ended-startTime").attr("disabled","disabled")
			}
			
			//已结束
			function chgState2() {
				$.ajax({
					type: "put",
					url: ip + setTimeUrl,
					data: {
						id: chgId,
						startTime: $("#ended-startTime").val(),
						endTime: $("#ended-endTime").val()
					},
					dataType: "json",
					//					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log(res);
						if(res.code == 0) {
							//先更改周期再更改状态
							$("#modal-ended").modal("toggle")
							$(".layui-laypage-btn").click();
						}else{
							$("#quesnote2").html(res.msg)
						}
						
					},
					async: true
				});
			}

			function chgState(id) {
				console.log(id);
				$.ajax({
					type: "put",
					url: ip + chgStateUrl,
					data: {
						id: id
					},
					dataType: "json",
					//					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log(res);
						//location.reload();
						$(".layui-laypage-btn").click();
						
						console.log("aaa")
					},
					async: true
				});
			}

			function transId(id) {
				chgId = id;
				console.log(chgId);
				
			}
			function transId1(id,str){
				chgId = id;
				console.log(id)
				if(str=="未开始"){
					$("#setTime-startTime").val(currentdate);
				}else{
					detail(id)
				}
			}
			
			function detail(id)
			{
				$.ajax({
					type: "get",
					url: ip + '/survey/detail',
					data: {
						id: id
					},
					dataType: "json",
					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log(res);
						$("#setTime-startTime").val(res.data.startTime);
						$("#setTime-endTime").val(res.data.endTime)
						$("#setTime-endTime").datepicker({
							minDate: res.data.startTime,
						});
						$('#setTime-startTime').attr("disabled",true);
					},
					async: true
				});
			}
			
			
			
			/* 删除调查 */
			var deleteId = '',
				deleteUrl = '/survey/delete'

			function trasnDelId(id) {
				console.log(id);
				deleteId = id;
			}

			function deleteSurvey() {
				var sh = deleteUrl + "?id=" + deleteId;

				$.ajax({
					type: "delete",
					url: ip + sh,
					//					data: {
					//						id: deleteId
					//					},
					dataType: "json",
					//					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log(res);
						if(res.code == 0) {
							//location.reload();
							$(".layui-laypage-btn").click();
							$("#modal-delete").modal("toggle")
						}
					},
					async: true
				});
			}

			var state = 'all',
				privately = null;

			var $type1 = $("#select-type-all"),
				$type2 = $("#select-type-open"),
				$type3 = $("#select-type-private"),
				$state1 = $("#select-state-all"),
				$state2 = $("#select-state-notStarted"),
				$state3 = $("#select-state-running"),
				$state4 = $("#select-state-paused"),
				$state5 = $("#select-state-ended");

			var $a1 = $("#select-type-all a"),
				$a2 = $("#select-type-open a"),
				$a3 = $("#select-type-private a"),
				$a4 = $("#select-state-all a"),
				$a5 = $("#select-state-notStarted a"),
				$a6 = $("#select-state-running a"),
				$a7 = $("#select-state-paused a"),
				$a8 = $("#select-state-ended a");

			var typeArray = new Array($type1, $type2, $type3),
				stateArray = new Array($state1, $state2, $state3, $state4, $state5);

			$a1.on('click', function() {
				setLiActive(typeArray, $type1);
				selectSurvey(null, 0,'');
			});

			$a2.on('click', function() {
				setLiActive(typeArray, $type2);
				selectSurvey(false, 0,'');
			});

			$a3.on('click', function() {
				setLiActive(typeArray, $type3);
				selectSurvey(true, 0,'');
			});

			$a4.on('click', function() {
				setLiActive(stateArray, $state1);
				selectSurvey('all', 1,'');
			});

			$a5.on('click', function() {
				setLiActive(stateArray, $state2);
				selectSurvey('notStarted', 1,'');
			});

			$a6.on('click', function() {
				setLiActive(stateArray, $state3);
				selectSurvey('running', 1,'');
			});

			$a7.on('click', function() {
				setLiActive(stateArray, $state4);
				selectSurvey('paused', 1,'');
			});

			$a8.on('click', function() {
				setLiActive(stateArray, $state5);
				selectSurvey('ended', 1,'');
			});

			function setLiActive(array, ele) {
				if(ele.hasClass("active")) {
					//do nothing
				} else {
					//遍历数组，移除其他的active
					for(var i = 0; i < array.length; i++) {
						var item = array[i];
						if(item.hasClass('active')) {
							item.removeClass('active');
						}
					}
					ele.addClass("active");
				}
			}

			function selectSurvey(dataq, type,pageconf) {
				if(!pageconf){
					pageconf={};
					pageconf.pageSize=6;
					pageconf.currentPage=1;
				}

				var selectUrl = '/survey/select',
					obj = {};

				if(type == 0) {
					privately = dataq;
				} else {
					state = dataq;
				}

				if(privately != null && state != 'all') {
					obj = {
						state: state,
						privately: privately,
						page:pageconf.currentPage,
						size:pageconf.pageSize
					}
				} else {
					if(privately != null) {
						obj = {
							privately: privately,
							page:pageconf.currentPage,
							size:pageconf.pageSize
						}
					}
					else if(state != 'all') {
						obj = {
							state: state,
							page:pageconf.currentPage,
							size:pageconf.pageSize
						}
					}
					else{
						getList();
						return true;
					}
				}
               //分页
				$.ajax({
					type: "get",
					url: ip + selectUrl,
					data: obj,
					dataType: "json",
					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						//setList(res.data);
						if(typeof res.data!="string"){
							total=res.data.total;
							getPagetrue(pageconf,res.data.datas,dataq,type)
							if($("#layui").hasClass("hidden"))
							{
								$("#layui").removeClass("hidden")
							}
						}else{
							total=0;
							getPagetrue(pageconf,0,dataq,type)
							$("#survey-list").html("<div style='color: darkgrey;text-align: center;'>当前调查列表为空</div>")
							$("#layui").addClass("hidden")
						}
						 
					},
					async: true
				});
			}
			
			//===========实名匿名的分页
			function getPagetrue(pageconf,date,dataq,type){
				layui.use(['laypage','layer'],function(){
					var laypage=layui.laypage;
					laypage.render({
						elem:'layui',
						count:total,
						skin:'#7c62ad',
						curr:pageconf.currentPage,
						limit:pageconf.pageSize,
						limits:[4,8,12],
						skip:true,
						first:"首页",
						last:"尾页",
						layout:['count','skip' ,'next', 'prev'],
						jump:function(obj,first){
							page=obj.curr;
							limit=obj.limit;
							if(!first){
								 pageconf.currentPage=obj.curr;
								 pageconf.pageSize=obj.limit;
								 selectSurvey(dataq,type,pageconf,);
							}
						}
					});
					setList(date);
				});
			}
			
			
			

			function createSurvey() {
				window.open("createSurvey.html", "_blank");
			}

			function surveyDetail(id, type) {
				console.log("=======");
				console.log(type);
				//若非公开，即实名
				if(type) {
					var url = "surveyDetail.html?id=" + id;
					window.open(url, "_blank");
				}
				//匿名
				else {
					var url = "surveyDetail_unreal.html?id=" + id;
					window.open(url, "_blank");
				}
			}

			/*完成情况*/
			function completeDetail(id) {
				var url = "completeSituation.html?id=" + id;
				window.open(url, "_blank");
			}

			/*答案查看*/
			function checkAnswer(id) {
				var url = "checkAnswer.html?id=" + id;
				window.open(url, "_blank");
			}
			function analysisAnswer(id)
			{
				var url="analysisAnswer.html?id="+id;
				window.open(url,"_blank");
			}
			
			
			//搜索===========================================
			 $('#input-search-survey').bind('input propertychange', function() {
    				searchCity();
  			});
  			 
  			 function searchCity(pageconf){
				if(!pageconf){
					pageconf={};
					pageconf.pageSize=6;
					pageconf.currentPage=1;
				}
				$.ajax({
					type: "get",
					url: ip + '/survey/search',
					data: {
						"page":pageconf.currentPage,
						"size":pageconf.pageSize,
						"word":$("#input-search-survey").val(),
					},
					//adataType: "json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log(res.data);
						//填充
						//setTable(res.data.content);
						if(typeof res.data !='string'){
							total=res.data.total;
							getPage2(pageconf,res.data.datas)
						}else{
							total=0;
							getPage(pageconf,0)
							$("#survey-list").html("<div style='color: darkgrey;text-align: center;'>当前调查列表为空</div>")
							$("#layui").addClass("hidden")
						}
					},
					async: true
				});
			}
			
			function getPage2(pageconf,date){
				layui.use(['laypage','layer'],function(){
					var laypage=layui.laypage;
					laypage.render({
						elem:'layui',
						count:total,
						skin:'#7c62ad',
						curr:pageconf.currentPage,
						limit:pageconf.pageSize,
						limits:[4,8,12],
						skip:true,
						first:"首页",
						last:"尾页",
						layout:['count','skip' ,'next', 'prev'],
						jump:function(obj,first){
							page=obj.curr;
							limit=obj.limit;
							if(!first){
								 pageconf.currentPage=obj.curr;
								 pageconf.pageSize=obj.limit;
								 searchCity(pageconf);
							}
						}
					});
					setList(date);
				});
			}
			
		</script>
	</body>

</html>